package com.TCP_UDP网络编程.homeWork;

import com.TCP_UDP网络编程.StreamUtils;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP2_Server {
    public static void main(String[] args) throws IOException {
        StringBuilder SrcFatherFilePath = new StringBuilder("java-code/src/com/网络编程/发送的图片/");
        ServerSocket serverSocket = new ServerSocket(9997);
        Socket socket = serverSocket.accept();

        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String s1 = br.readLine();
        System.out.println(s1);
        for (int i = 1; i <= 5; i++) {
            if (s1.equals(""+i)) {
                SrcFatherFilePath.append(i+".png");
                break;
            }
        }

        FileInputStream fis = new FileInputStream(SrcFatherFilePath.toString());
        byte[] bytes = StreamUtils.StreamToByte(fis);
        socket.getOutputStream().write(bytes);


        is.close();
        socket.close();
        serverSocket.close();
    }

}